package com.glorysoft.hlgdpda.ui.trackin.view

import android.os.Bundle
import com.glorysoft.hlgdpda.BR
import com.glorysoft.hlgdpda.R
import com.glorysoft.hlgdpda.base.BaseActivity
import com.glorysoft.hlgdpda.databinding.ActivityBatchTrackIn2Binding
import com.glorysoft.hlgdpda.entity.ui.ToastMessageBean
import com.glorysoft.hlgdpda.ui.trackin.viewmodel.TrackInViewModel
import kotlinx.android.synthetic.main.activity_batch_track_in2.*

/**
 * FileName: BatchTrackIn2Activity
 * Author: XJH
 * Date: 2021/6/28 16:56
 * Description:
 * History:
 */
class BatchTrackIn2Activity : BaseActivity<TrackInViewModel,ActivityBatchTrackIn2Binding>() {
    override fun layoutId(): Int {
        return R.layout.activity_batch_track_in2
    }

    override fun initVariableId(): Int {
        return BR.trackInViewModel
    }

    override fun initView(savedInstanceState: Bundle?) {
        rvLotList.setEmptyView(lotEmptyView)
        setTitle("按Batch进站")
        viewModel.defUI.startActivity.observe(this){finish()}
        setRightListener("提交"){
            if (etLot.text.toString().isEmpty()){
                viewModel.defUI.toastEvent.value = ToastMessageBean("请扫描Batch号",false)
                return@setRightListener
            }

            viewModel.batchTrackIn2(etLot.text.toString(),etEqpWorkID.text.toString())
        }
    }

    override fun initData() {
        initEdit(etLot,object : EditTextListener{
            override fun onTextChangeListener(s: String) {
                viewModel.searchBatchInfo(s)
            }

        })

        viewModel.defUI.callObserve.observe(this){
            if (it.type == 210){
                tvCount.text = it.item.toString()
            }
            when(it.type){
                210 ->tvCount.text = it.item.toString()
                220 ->{
                    tvCount.text = "0"
                    etLot.setText("")
                    etEqpWorkID.setText("")
                }
            }
        }
    }
}